package com.appspot.peachykene.impl;

import java.util.Properties;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.appspot.peachykene.Email;

public class GoogleEmailImpl implements Email{
	private String subject;
	private String body;
	private String sender;
	private String recepient;
		
	@Override
	public void setSender(String sender) {
		this.sender = sender;		
	}

	@Override
	public void setRecepient(String recepient) {
		this.recepient = recepient;
	}

	@Override
	public void setSubect(String subject) {
		this.subject = subject;
	}

	@Override
	public void setBody(String body) {
		this.body = body;
	}

	@Override
	public boolean send() {
		Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);

        try {
            Message msg = new MimeMessage(session);
            Address inbox = new InternetAddress(recepient, "Peachykene Contact Email");
            msg.setFrom(inbox);
            msg.setReplyTo(new Address[] { new InternetAddress(sender) });
            msg.addRecipient(Message.RecipientType.TO, inbox);
            msg.setSubject(subject);
            msg.setText(body);
            Transport.send(msg);
        } catch (Exception ex) {
        	throw new RuntimeException(ex);
        }
        return true;
	}
	
}
